package com.csii.ssm.context;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.util.Properties;

/**
 * Created by Myang on 2016/4/24.
 */
public class ModeControllerUtil {

    private static final Logger logger = LoggerFactory.getLogger(ModeControllerUtil.class);

    private static Properties prop;

    public static String MODE;//模式 DEV为开发模式  PRO为生产模式

    private static final String CONFIG_FILE_PATH = "/configs.xml";

    static {
        try {
            prop = new Properties();
            InputStream input = ModeControllerUtil.class.getResourceAsStream(CONFIG_FILE_PATH);
            prop.loadFromXML(input);
        } catch (Exception e) {
            e.printStackTrace();
        }

        MODE = prop.getProperty("CurrentMode");//读取模式
    }

    public static String getServletConfigLocation() {
        String[] configLocations = prop.getProperty(MODE).split(",");
        String contextConfigLocation = configLocations[1];//获取spring mvc配置文件路径
        return contextConfigLocation;
    }

    public static String[] getApplicationContextConfigLocation() {
        String[] configLocations = prop.getProperty(MODE).split(",");
        String contextConfigLocation = configLocations[0];//获取applicatioin配置文件路径
        return new String[]{contextConfigLocation};
    }

}
